package research.entity;

import java.util.ArrayList;
import java.util.List;

import research.domain.Application;
import research.domain.Calander;
import research.domain.Component;
import research.domain.ComponentType;
import research.domain.ComponentValue;
import research.domain.DefaultParameterValue;
import research.domain.FilmType;
import research.domain.Formula;
import research.domain.Mixer;
import research.domain.Parameter;
import research.domain.ParameterValue;
import research.domain.Photo;
import research.domain.Point;
import research.domain.Preparation;
import research.domain.Production;
import research.domain.Research;
import research.domain.Result;
import research.domain.Sample;
import research.domain.SampleStabilizer;
import research.domain.Scratch;
import research.domain.Stabilizer;
import research.domain.Strength;
import research.domain.StrengthValue;
import research.domain.Test;
import research.domain.TestParameter;
import research.domain.TestParameterValue;
import research.domain.TestResult;
import research.domain.TestType;
import research.domain.Viscosity;
import research.domain.ViscosityValue;
import research.ui.editors.ApplicationEditor;
import research.ui.editors.CalanderEditor;
import research.ui.editors.ComponentEditor;
import research.ui.editors.ComponentTypeEditor;
import research.ui.editors.FilmTypeEditor;
import research.ui.editors.FormulaEditor;
import research.ui.editors.MixerEditor;
import research.ui.editors.PhotoEditor;
import research.ui.editors.PreparationEditor;
import research.ui.editors.ProductionEditor;
import research.ui.editors.ResearchEditor;
import research.ui.editors.ResultEditor;
import research.ui.editors.SampleEditor;
import research.ui.editors.SampleStabilizerEditor;
import research.ui.editors.ScratchEditor;
import research.ui.editors.StabilizerEditor;
import research.ui.editors.StrengthEditor;
import research.ui.editors.TestEditor;
import research.ui.editors.TestTypeEditor;
import research.ui.editors.ViscosityEditor;

public class EntityType {
	private final Class<?> entityClass;
	private final String editorId;
	private final String iconUri;
	private final String name;
	private final String forName;
	private final String report;
	private List<EntityType> children;

	public EntityType(String name, Class<?> entityClass, String editorId, String iconUri, String forName, String report) {
		super();
		this.name = name;
		this.forName = forName;
		this.entityClass = entityClass;
		this.editorId = editorId;
		this.iconUri = iconUri;
		this.report = report;
		this.children = new ArrayList<EntityType>();
	}

	public Class<?> getEntityClass() {
		return entityClass;
	}
	
	public String getEditorId() {
		return editorId;
	}
	
	public String getIconUri() {
		return iconUri;
	}
	
	public String getName() {
		return name;
	}
	
	public String getForName() {
		return forName;
	}

	public List<EntityType> getChildren() {
		return children;
	}
	
	public String getReport() {
		return report;
	}

	private EntityType addChildType(EntityType type) {
		children.add(type);
		return this;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof EntityType) {
			EntityType type = (EntityType) obj;
			return type.entityClass.equals(this.entityClass);
		}
		return super.equals(obj);
	}



	public static EntityType Application = new EntityType("Заявка", Application.class, ApplicationEditor.ID, "icons/application.png", "заявки", "order.jasper");
	public static EntityType Calander = new EntityType("Каландровая линия", Calander.class, CalanderEditor.ID, "icons/calander.png", "каландровой линии", null);
	public static EntityType ComponentValue = new EntityType("Содержание компонента", ComponentValue.class, null, null, "содержания компонента", null);
	public static EntityType Component = new EntityType("Компонент рецептуры", Component.class, ComponentEditor.ID, "icons/component.png", "компонента", null);
	public static EntityType Photo = new EntityType("Испытание способности к печати", Photo.class, PhotoEditor.ID, "icons/photo.png", "испытания способности к печати", null);
	public static EntityType Scratch = new EntityType("Испытание стойкости к царапинам", Scratch.class, ScratchEditor.ID, "icons/scratch.png", "испытания стойкости к царапинам", null);
	public static EntityType Strength = new EntityType("Испытание прочности на растяжение", Strength.class, StrengthEditor.ID, "icons/strength.png", "испытания прочности на растяжение", "strength.jasper");
	public static EntityType Viscosity = new EntityType("Испытание ударной вязкости", Viscosity.class, ViscosityEditor.ID, "icons/viscosity.png", "испытания ударной вязкости", "viscosity.jasper");
	public static EntityType Formula = new EntityType("Рецептура", Formula.class, FormulaEditor.ID, "icons/formula.png", "рецептуры", null);
	public static EntityType ParameterValue = new EntityType("Значение параметра", ParameterValue.class, null, null, "значения параметра", null);
	public static EntityType Parameter = new EntityType("Технологический параметр", Parameter.class, null, null, "технологического параметра", null);
	public static EntityType Point = new EntityType("Точка", Point.class, null, null, "точки", null);
	public static EntityType Preparation = new EntityType("Описание смешения", Preparation.class, PreparationEditor.ID, "icons/preparation.png", "описания смешения", null);
	public static EntityType Research = new EntityType("Исследование", Research.class, ResearchEditor.ID, "icons/research.png", "исследования", "research.jasper");
	public static EntityType Result = new EntityType("Результат исследования", Result.class, ResultEditor.ID, "icons/result.png", "результата исследования", null);
	public static EntityType SampleStabilizer = new EntityType("Образец стабилизатора", SampleStabilizer.class, SampleStabilizerEditor.ID, "icons/sample_stabilizer.png", "образца стабилизатора", null);
	public static EntityType Sample = new EntityType("Образец", Sample.class, SampleEditor.ID, "icons/sample.png", "образца", null);
	public static EntityType Stabilizer = new EntityType("Испытание стабилизатора", Stabilizer.class, StabilizerEditor.ID, "icons/stabilizer.png", "испытания стабилизатора", null);
	public static EntityType StrengthValue = new EntityType("Значение прочности", StrengthValue.class, null, null, "значения прочности", null);
	public static EntityType ViscosityValue = new EntityType("Значение вязкости", ViscosityValue.class, null, null, "значения вязкости", null);
	public static EntityType FilmType = new EntityType("Тип пленки", FilmType.class, FilmTypeEditor.ID, "icons/film_type.png", "типа пленки", null);
	public static EntityType TestType = new EntityType("Тип испытания", TestType.class, TestTypeEditor.ID, "icons/test_type.png", "типа испытания", null);
	public static EntityType TestParameter = new EntityType("Параметр испытания", TestParameter.class, null, null, "параметра испытания", null);
	public static EntityType TestParameterValue = new EntityType("Значение параметра испытания", TestParameterValue.class, null, null, "значения параметра испытания", null);
	public static EntityType Test = new EntityType("Другое испытание", Test.class, TestEditor.ID, "icons/test.png", "другого испытания", "other.jasper");
	public static EntityType Mixer = new EntityType("Сместиель", Mixer.class, MixerEditor.ID, "icons/mixer.png", "смесителя", null);
	public static EntityType ComponentType = new EntityType("Тип компонента рецептуры", ComponentType.class, ComponentTypeEditor.ID, "icons/component_type.png", "типа компонента рецептуры", null);
	public static EntityType Production = new EntityType("Описание изготовления образца", Production.class, ProductionEditor.ID, "icons/production.png", "описания изготовления образца", "production.jasper");
	public static EntityType DefaultParameterValue = new EntityType("Значение параметра по умолчанию", DefaultParameterValue.class, null, null, "значения параметра по умолчанию", null);
	public static EntityType TestResult = new EntityType("Показатель качества образца", TestResult.class, null, null, "показателя качества", "test_result.jasper");
	
	static {
		Application.addChildType(Research);
		
		Calander.addChildType(Production)
			.addChildType(Application);
		
		Formula.addChildType(Sample);
		
		Preparation.addChildType(Production);
		
		Research.addChildType(Production)
			.addChildType(Stabilizer);
		
		Result.addChildType(Research);
		
		Sample.addChildType(Test)
			.addChildType(Strength)
			.addChildType(Viscosity)
			.addChildType(Photo)
			.addChildType(Scratch)
			.addChildType(SampleStabilizer);
		
		Stabilizer.addChildType(SampleStabilizer);
		
		FilmType.addChildType(Application)
			.addChildType(Sample);
		
		TestType.addChildType(Test);
		
		Mixer.addChildType(Preparation);
		
		ComponentType.addChildType(Component);
		
		Production.addChildType(Sample);
	}
}
